package cn.dulian.spring5.testdemo;

import cn.dulian.spring5.autowire.Emp;
import cn.dulian.spring5.bean.Orders;
import cn.dulian.spring5.collectiontype.Book;
import cn.dulian.spring5.collectiontype.Course;
import cn.dulian.spring5.collectiontype.Stu;
import com.alibaba.druid.pool.DruidDataSource;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author dulian
 * @create 2022-04-14 23:20
 */
public class TestSpring5Demo {
    @Test
    public void testCollection1(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        Stu stu = context.getBean("stu", Stu.class);
        stu.test();

    }

    @Test
    public void testCollection2(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("bean2.xml");
        Book book = context.getBean("book", Book.class);
        book.test();

    }

    @Test
    public void test3() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean3.xml");
        Course course = context.getBean("myBean", Course.class);
        System.out.println(course);
    }

    @Test
    public void test4() {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("bean4.xml");
        Orders orders = context.getBean("orders", Orders.class);
        System.out.println("第四步 获取创建bean实例对象");
        System.out.println(orders);
        //手动让bean实例销毁
        context.close();
    }

    @Test
    public void test5() {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("bean5.xml");
        Emp emp = context.getBean("emp", Emp.class);
        System.out.println(emp);
    }

    @Test
    public void test6() {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("bean6.xml");
        DruidDataSource emp = context.getBean("dataSource", DruidDataSource.class);
        System.out.println(emp);
    }
}
